***********************************************************************************
***	Replication file for:                                                     	***
*** Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of 			***
***	Being Widowed by War: A Life-Cycle Perspective.	     						***
***																				***
***	Journal of Public Economics                                                 ***
***   							                                                ***
*** Script:		_11a-ghs-2-prep-cross-section-A.do				   			 	***	
*** Purpose:	data preparation, cross-sectional data GHS-2, Survey A			***
***																				***
***********************************************************************************


***
* Note: Time variable t counts months since 01/1900 
***


*** Generation index

/*
1001 "Leiblicher Vater der Indexperson (Großvater)"
1002 "Leibliche Mutter der Indexperson (Großmutter)"
1003 "Stief-/Pflegevater der Indexperson (Großvater)"
1004 "Stief-/Pflegemutter der Indexperson (Großmutter)"

2001 "Indexperson"

2002 "Ehepartner 1 der Indexperson"
2003 "Ehepartner 2 der Indexperson"
2004 "Ehepartner 3 der Indexperson"
*/


/*
1001 "Biological father of index person (grandfather)"
1002 "Biological mother of index person (grandmother)"
1003 "Stepfather/foster father of the index person (grandfather)"
1004 "Stepmother/foster mother of the index person (grandmother)"

2001 "Index person"

2002 "Spouse 1 of the index person"
2003 "Spouse 2 of the index person"
2004 "Spouse 3 of the index person"
*/


**************************************************
* Cross-sectional data for index person
**************************************************

***********************************************
* RECORD 01 PA – Allgemeine Personenangaben –
* RECORD 01 PA – General personal data –
***********************************************

use "$widowsghs/Data/LV2A/PA.dta", clear

rename APA01 geschlecht
label var geschlecht "APA01: Sex (1=male, 2=female)"
recode geschlecht 7/9 = .

rename APA02 geburtsjahr
replace geburtsjahr = geburtsjahr + 1900
label var geburtsjahr "APA02: Year of birth"
recode geburtsjahr 97/99 = .

rename APA03 geburtsmonat
label var geburtsmonat "APA03: Month of birth"
recode geburtsmonat 97/99 = . 

rename APA08 schulabschluss
label var schulabschluss "APA08: Highest school-leaving qualification"
recode schulabschluss 8/9 = .

tab APA26
recode APA26 97/99 = .
rename APA26 marital_status
label var marital_status "Current marital status"

* Interview date
gen interview_date = APA39 * 12 + APA40
label var interview_date "Interview date (in month since 1900)"

drop APA*
compress

sort AIDN

save "$widowsghs/processed/intermediate/01_PA_CS_LV2A.dta", replace


*********************************************
* RECORD 05 HG - Anzahl Geschwister - 
* RECORD 05 HG - Number of siblings - 
*********************************************

use "$widowsghs/Data/LV2A/HG.dta", clear

bysort AIDN: egen anz_geschwister = max(AIDHG)
label var anz_geschwister "Number of siblings"

keep if AIDHG == 1

keep AIDN anz_*

save "$widowsghs/processed/intermediate/anzgeschw_CS_LV2A.dta", replace

*********************************************************************************
* RECORD 13 AB – Angaben zur beruflichen Bildung
* RECORD 13 AB - Information on vocational training
*********************************************************************************

use "$widowsghs/Data/LV2A/AB.dta", clear

egen anzahl_ausbildungen=max(AIDAB), by(AIDN)
label var anzahl_ausbildungen "Number of vocational trainings"

forvalues t = 1/12 {
gen double help_`t'=.
replace help_`t' = AAB11 if AIDAB == `t'
recode help_`t' 97/99 = .
egen double ausbildungsabschluss_`t'=max(help_`t'), by(AIDN)
label var ausbildungsabschluss_`t' "Completion of training i"
drop help_`t'
}

gen lehre_gewerblich = 0
forvalues t = 1/12 {
replace lehre_gewerblich = 1 if ausbildungsabschluss_`t' == 31 | ausbildungsabschluss_`t' == 42
}
label var lehre_gewerblich "AAB11: Industral apprenticeship"

gen lehre_landwirtschaft = 0
forvalues t = 1/12 {
replace lehre_landwirtschaft = 1 if ausbildungsabschluss_`t' == 32
}
label var lehre_landwirtschaft "AAB11: Agrarian/domestic apprenticeship (Land-/Hauswirtschaftslehre)"

gen lehre_kaufm = 0
forvalues t = 1/12 {
replace lehre_kaufm = 1 if ausbildungsabschluss_`t' == 33 | ausbildungsabschluss_`t' == 43
}
label var lehre_kaufm "AAB11: Commercial apprenticeship (kaufmännisch), administrative apprenticeship"

gen berufsfachschule = 0
forvalues t = 1/12 {
replace berufsfachschule = 1 if ausbildungsabschluss_`t' == 21 | ausbildungsabschluss_`t' == 22
}
label var berufsfachschule "AAB11: Completion of a vocational school/technical college"

gen fachhochschulabschluss = 0
forvalues t = 1/12 {
replace fachhochschulabschluss = 1 if ausbildungsabschluss_`t' == 23 | ausbildungsabschluss_`t' == 24
}
label var fachhochschulabschluss "AAB11: Degree from a university of applied sciences/vocational academy"

gen uniabschluss = 0
forvalues t = 1/12 {
replace uniabschluss = 1 if ausbildungsabschluss_`t' == 25 | ausbildungsabschluss_`t' == 26 | ausbildungsabschluss_`t' == 27 
}
label var uniabschluss "AAB11: University degree (Staatsexamen/Diplom/Magister)"

gen promotion = 0
forvalues t = 1/12 {
replace promotion = 1 if ausbildungsabschluss_`t' == 28 
}
label var promotion "AAB11: Doctoral degree"

gen einf_dienst = 0
forvalues t = 1/12 {
replace einf_dienst = 1 if ausbildungsabschluss_`t' == 41
}
label var einf_dienst "AAB11: Degree lower public service (einfacher Dienst)"

gen mitt_dienst = 0
forvalues t = 1/12 {
replace mitt_dienst = 1 if ausbildungsabschluss_`t' == 44 | ausbildungsabschluss_`t' == 45
}
label var mitt_dienst "AAB11: Degree intermediate public service (mittlerer Dienst)"

gen geh_dienst = 0
forvalues t = 1/12 {
replace geh_dienst = 1 if ausbildungsabschluss_`t' == 46
}
label var geh_dienst "AAB11: Degree higher public service (gehobener Dienst)"

gen hoh_dienst = 0
forvalues t = 1/12 {
replace hoh_dienst = 1 if ausbildungsabschluss_`t' == 47
}
label var hoh_dienst "AAB11: Degree high public service (höherer Dienst)"

gen sonst_abschluss = 0
forvalues t = 1/12 {
replace sonst_abschluss = 1 if ausbildungsabschluss_`t' == 30 | ausbildungsabschluss_`t' == 40
}
label var sonst_abschluss "AAB11: Other degree"

gen meisterabschluss = 0
forvalues t = 1/12 {
replace meisterabschluss = 1 if ausbildungsabschluss_`t' == 51
}
label var meisterabschluss "AAB11: Graduation as a master craftsman"

*** Generate variable for training analogous to coding for parents and children
/*
(0) SONSTIGER ABSCHLUSS
(1) GEWERBLICHE LEHRE
(2) KAUFMÄNNISCHE LEHRE/VERWALTUNGSLEHRE
(3) HAUSWIRTSCHAFTS-/LANDWIRTSCHAFTSLEHRE
(4) BERUFSFACHSCHULE
(5) PRAKTIKUM/VOLONTARIAT
(6) MEISTER
(7) FACHHOCHSCHULE
(8) UNIVERSITÄT
(9) KEINE AUSBILDUNG/OHNE ABSCHLUSS
*/
/*
(0) OTHER DEGREE
(1) INDUSTRIAL APPRENTICESHIP
(2) COMMERCIAL/ADMINISTRATIVE APPRENTICESHIP
(3) HOME ECONOMICS/AGRICULTURE
(4) VOCATIONAL COLLEGE
(5) INTERNSHIP/VOLUNTARIAT
(6) MASTER CRAFTSMAN
(7) UNIVERSITY OF APPLIED SCIENCES
(8) UNIVERSITY
(9) NO TRAINING/NO DEGREE
*/

gen berufsausbildung = 9
replace berufsausbildung = 3 if lehre_landwirtschaft == 1
replace berufsausbildung = 1 if lehre_gewerblich == 1
replace berufsausbildung = 4 if berufsfachschule == 1
replace berufsausbildung = 2 if lehre_kaufm == 1
replace berufsausbildung = 6 if meisterabschluss == 1
replace berufsausbildung = 7 if fachhochschulabschluss == 1
replace berufsausbildung = 8 if uniabschluss == 1 | promotion == 1
replace berufsausbildung = 0 if berufsausbildung == 9 & (einf_dienst == 1 | mitt_dienst == 1 | geh_dienst == 1 | hoh_dienst == 1 | sonst_abschluss == 1)


*label define berufsausbl 0 "SONSTIGER ABSCH. (OEFF. DIENST)" 1 "GEWERBLICHE LEHRE" 2 "KAUFMÄNNISCHE LEHRE/VERWALTUNGSLEHRE" 3 "HAUSWIRTSCHAFTS-/LANDWIRTSCHAFTSLEHRE" 4 "BERUFSFACHSCHULE" 5 "PRAKTIKUM/VOLONTARIAT" 6 "MEISTER" 7 "FACHHOCHSCHULE" 8 "UNIVERSITÄT" 9 "KEINE AUSBILDUNG/OHNE ABSCHLUSS"

label define berufsausbl 0 "OTHER DEGREE (PUBLIC SERVICE)" 1 "INDUSTRIAL APPRENTICESHIP" 2 "COMMERCIAL/ADMINISTRATIVE APPRENTICESHIP" 3 "HOME ECONOMICS/AGRICULTURE APPRENTICESHIP" 4 "VOCATIONAL COLLEGE" 5 "INTERNSHIP/VOLONTARIAT" 6 "MASTER CRAFTSMAN" 7 "UNIVERSITY OF APPLIED SCIENCES" 8 "UNIVERSITY" 9 "NO APPRENTICESHIP/NO DEGREE"
label values berufsausbildung berufsausbl
label var berufsausbildung "AAB11: Highest educational qualification"

* Speichern

keep if AIDAB == 1
keep AIDN berufsausbildung 

compress

sort AIDN
save "$widowsghs/processed/intermediate/13_AB_CS_LV2A.dta", replace

*********************************************************************************
* RECORD 15 BG – Angaben zum Erwerbsverlauf
* RECORD 15 BG – Information on the employment history
*********************************************************************************

use "$widowsghs/Data/LV2A/BG.dta", clear
merge m:m AIDN using "$widowsghs/processed/intermediate/01_PA_CS_LV2A.dta", keepusing(geburtsjahr)
drop _merge
drop if AIDBG == .

* Recoding Prestige
* Code Prestige as missing, if occupation is missing, still in training or retired/pensioner
replace ABG02 = . if (ABG01 == 8 | ABG01 == 9 | ABG01 == 5 | ABG01 == 7) 
replace ABG27 = . if (ABG01 == 8 | ABG01 == 9 | ABG01 == 5 | ABG01 == 7) 
* Code Prestige as 0 if jobseeker or non-employed housewife
replace ABG02 = 0 if ABG01 == 3 | ABG01 == 6
replace ABG27 = 0 if ABG01 == 3 | ABG01 == 6
* Replace prestige value of 0 with missing if profession is indeterminable or inadequately described
recode ABG02 0 = . if ABG01 == 4
recode ABG27 0 = . if ABG01 == 4

* Highest prestige value achieved in the course of employment (Treiman)
bysort AIDN: egen beruf_prestige_max_tr = max(ABG02)
recode beruf_prestige_max_tr . = -9
label var beruf_prestige_max_tr "ABG02: Highest prestige value achieved (Treiman)"

* Highest prestige value achieved in the course of employment (Wegener)
bysort AIDN: egen beruf_prestige_max_wg = max(ABG27)
recode beruf_prestige_max_wg . = -9
label var beruf_prestige_max_wg "ABG27: Highest prestige value achieved (Wegener)"

* Keep only one spell, drop superfluous variables and save
keep if AIDBG == 1
keep AIDN beruf*

compress

sort AIDN


save "$widowsghs/processed/intermediate/15_BG_CS_LV2A.dta", replace


**********************************
* Record 25 FK Anzahl Kinder
* Record 25 FK Number of children
**********************************

use "$widowsghs/Data/LV2A/FK.dta", clear

bysort AIDN: egen anz_kinder = max(AIDFK)
label var anz_kinder "Number of children"

keep if AIDFK == 1

keep AIDN anz_kinder

save "$widowsghs/processed/intermediate/anzkinder_CS_LV2A.dta", replace



**************************************************
* Merging the data on index person
**************************************************

use "$widowsghs/processed/intermediate/01_PA_CS_LV2A.dta", clear

merge m:m AIDN using "$widowsghs/processed/intermediate/13_AB_CS_LV2A.dta"
drop _merge

merge m:m AIDN using "$widowsghs/processed/intermediate/anzkinder_CS_LV2A.dta"
drop _merge

merge m:m AIDN using "$widowsghs/processed/intermediate/anzgeschw_CS_LV2A.dta"
drop _merge

merge m:m AIDN using "$widowsghs/processed/intermediate/15_BG_CS_LV2A.dta"
drop _merge

recode berufsausbildung . = 9
recode anz_kinder anz_geschwister (. = 0)

* Recoding: For never-employed persons, the employment history is missing, variables are set to . when merging => code to "not-employed"

recode beruf_prestige_max_tr . = 0
recode beruf_prestige_max_tr -9 = .
recode beruf_prestige_max_wg . = 0
recode beruf_prestige_max_wg -9 = .


gen index = 2001

save "$widowsghs/processed/intermediate/A_Indexperson_CS_LV2A.dta", replace


***********************************************
* Spouse of the index person
***********************************************

************************************************
* RECORD 23 FP – Angaben zu Ehe/Partnerschaft
* RECORD 23 FP – Details of marriage/partnership
************************************************

forvalues t = 1/3 {

use "$widowsghs/Data/LV2A/FP.dta", clear
keep if AIDFP == `t'

rename AFP01 heiratsjahr 
label var heiratsjahr "AFP01: Date of marriage, year"
recode heiratsjahr 97/99 = .

rename AFP02 heiratsmonat
label var heiratsmonat "AFP02: Date of marriage, month"
recode heiratsmonat 0 = .

rename AFP03 scheidungsjahr
label var scheidungsjahr "AFP03: Year of divorce"
recode scheidungsjahr 0 = .
recode scheidungsjahr 98/99 = .

rename AFP05 todesjahr
label var todesjahr "AFP05: Year of death (95 = missing in action)"
recode todesjahr 97/99 = .
replace todesjahr = todesjahr + 1900 if todesjahr != 95

rename AFP06 trennungsjahr
label var trennungsjahr "AFP06: Year of separation"
recode trennungsjahr 97/99 = .

rename AFP07 geburtsjahr
label var geburtsjahr "AFP07: Year of birth of the spouse"
recode geburtsjahr 9997/9999 = .

rename AFP08 schulabschluss
label var schulabschluss "AFP08: School-leaving certificate of the spouse"
recode schulabschluss 8/9 = .

rename AFP13 berufsausbildung
label var berufsausbildung "AFP13: Vocational training of the spouse"
recode berufsausbildung 96/99 = .

gen trennungsjahr_gen = .
replace trennungsjahr_gen = scheidungsjahr if scheidungsjahr !=. & scheidungsjahr != .t
replace trennungsjahr_gen = todesjahr if todesjahr != . & todesjahr !=.t
replace trennungsjahr_gen = trennungsjahr if trennungsjahr != . & trennungsjahr != .t
label var trennungsjahr_gen "AFP03/05/06: Generated year of separation (from info on year of divorce/death/separation)"

gen index = 2001 + `t'

drop AFP* AIDFP
compress

save "$widowsghs/processed/intermediate/A_Ehepartner`t'_CS_LV2A.dta", replace
}


***********************************************
* Mother of the index generation
***********************************************

*****************************************************
* RECORD 02 HM – Angaben zur leiblichen Mutter –
* RECORD 02 HM – Details of the biological mother –
*****************************************************

use "$widowsghs/Data/LV2A/HM.dta", clear

keep if AIDHM == 1

rename AHM01 geburtsjahr
label var geburtsjahr "AHM01: Year of birth of the biological mother (9996: mother unknown)"
recode geburtsjahr 9996/9999 = .

rename AHM03 todesjahr
label var todesjahr "AHM03: Year of death of the biological mother"
recode todesjahr 97/99 = .
recode todesjahr 0 = .
replace todesjahr = todesjahr + 1900

rename AHM05 schulabschluss
label var schulabschluss "AHM05: School-leaving certificate of the biological mother"
recode schulabschluss 8/9 = .

rename AHM10 berufsausbildung
label var berufsausbildung "AHM10: Vocational training of the biological mother"
recode berufsausbildung 97/99 = .
recode berufsausbildung 0 = 9 /* code "does not apply" (as no profession learned) as no vocational training */

drop AHM* AIDHM

gen index = 1002

compress

save "$widowsghs/processed/intermediate/B_Mutter_CS_LV2A.dta", replace

**********************************************************
* RECORD 02 HM – Angaben zur Stief-/Pflegemutter
* RECORD 02 HM – Details of the stepmother/foster mother
**********************************************************

use "$widowsghs/Data/LV2A/HM.dta", clear

keep if AIDHM == 2

rename AHM01 geburtsjahr
label var geburtsjahr "AHM01: Year of birth of the stepmother/foster mother (9996: mother unknown)"
recode geburtsjahr 9996/9999 = .

rename AHM03 todesjahr
label var todesjahr "AHM03: Year of death of the stepmother/foster mother"
recode todesjahr 97/99 = .
recode todesjahr 0 = .
replace todesjahr = todesjahr + 1900

rename AHM05 schulabschluss
label var schulabschluss "AHM05: School-leaving certificate of the stepmother/foster mother"
recode schulabschluss 8/9 = .

rename AHM10 berufsausbildung
label var berufsausbildung "AHM10: Vocational training of the stepmother/foster mother"
recode berufsausbildung 97/99 = .
recode berufsausbildung 0 = 9 /* code "does not apply" (as no profession learned) as no vocational training */

drop AHM* AIDHM

gen index = 1004

compress

save "$widowsghs/processed/intermediate/B_Stiefmutter_CS_LV2A.dta", replace

***********************************************
* Father of the index person
***********************************************

*****************************************************
* RECORD 03 HV – Angaben zum leiblichen Vater –
* RECORD 03 HV – Details of the biological father –
*****************************************************

use "$widowsghs/Data/LV2A/HV.dta", clear

keep if AIDHV == 1

rename AHV01 geburtsjahr
label var geburtsjahr "AHV01: Year of birth of the biological father (9996: father unknown)"
recode geburtsjahr 9996/9999 = .

rename AHV03 todesjahr
label var todesjahr "AHV03: Year of death of the biological father"
recode todesjahr 97/99 = .
recode todesjahr 0 = .
replace todesjahr = todesjahr + 1900

rename AHV06 schulabschluss
label var schulabschluss "AHV06: School-leaving certificate of the biological father"
recode schulabschluss 8/9 = .

rename AHV11 berufsausbildung
label var berufsausbildung "AHV11: Vocational training of the biological father"
recode berufsausbildung 97/99 = .

** Occupation learned

rename AHV07 beruf_erlernt
label var beruf_erlernt "AHV07: Learned profession of the biological father (ISCO)"
recode beruf_erlernt 8/9 = .

rename AHV08 beruf_erlernt_prestige_tr
label var beruf_erlernt_prestige_tr "AHV08: Prestige of the profession learned by the biological father (Trei)"

rename AHV33 beruf_erlernt_prestige_wg
label var beruf_erlernt_prestige_wg "AHV33: Prestige of the profession learned by the biological father (Wegener)"

** Occupation when index person was 15 years old

rename AHV12 beruf_ip15j_jn
recode beruf_ip15j_jn 8/9 = .

rename AHV13 beruf_ip15j 
label var beruf_ip15j "AHV13: Occupation that the biological father practiced when IP was 15 years old (ISCO)"
recode beruf_ip15j 8/9 = .

rename AHV14 beruf_ip15j_prestige_tr 
label var beruf_ip15j_prestige_tr "AHV14: Prestige of the profession that the biological father practiced when IP was 15 years old (TREI)"

rename AHV34 beruf_ip15j_prestige_wg 
label var beruf_ip15j_prestige_wg "AHV34: Prestige of the profession that the biological father practiced when IP was 15 years old (Wegener)"

** Occupation before index person was 15 years olds (if father was not gainfully employed when IP was 15 years old)

rename AHV18 beruf_vip15j 
label var beruf_vip15j "AHV18: Occupation that the biological father practiced before the IP was 15 years old (ISCO)"
recode beruf_vip15j 8/9 = .

rename AHV19 beruf_vip15j_prestige_tr 
label var beruf_vip15j_prestige_tr "AHV19: Prestige of the profession practiced by the biological father before IP 15 yrs old (TREI)"

rename AHV35 beruf_vip15j_prestige_wg 
label var beruf_vip15j_prestige_wg "AHV19: Prestige of the profession practiced by the biological father before IP 15 yrs old (Wegener)"

* Occupation before retirement/death

rename AHV23 beruf_vRuhe 
label var beruf_vRuhe "AHV23: Profession that the biological father practiced before retirement/death"
recode beruf_vRuhe 8/9 = .

rename AHV24 beruf_vRuhe_prestige_tr 
label var beruf_vRuhe_prestige_tr "AHV24: Prestige of the profession practiced by the biological father before retirement/death (TREI)"

rename AHV36 beruf_vRuhe_prestige_wg 
label var beruf_vRuhe_prestige_wg "AHV36: Prestige of the profession practiced by the biological father before retirement/death (Wegener)"


drop AHV* AIDHV

gen index = 1001

compress

save "$widowsghs/processed/intermediate/B_Vater_CS_LV2A.dta", replace


***********************************************************
* RECORD 03 HV – Angaben zum Stief-/Pflegevater –
* RECORD 03 HV – Details of the stepfather/foster father –
***********************************************************

use "$widowsghs/Data/LV2A/HV.dta", clear

keep if AIDHV == 2

rename AHV01 geburtsjahr
label var geburtsjahr "AHV01: Year of birth of the stepfather/foster father (9996: father unknown)"
recode geburtsjahr 9996/9999 = .

rename AHV03 todesjahr
label var todesjahr "AHV03: Year of death of the stepfather/foster father"
recode todesjahr 97/99 = .
recode todesjahr 0 = .
replace todesjahr = todesjahr + 1900

rename AHV06 schulabschluss
label var schulabschluss "AHV06: School-leaving certificate of the stepfather/foster father"
recode schulabschluss 8/9 = .

rename AHV11 berufsausbildung
label var berufsausbildung "AHV11: Vocational training of the stepfather/foster father"
recode berufsausbildung 97/99 = .

** Occupation learned

rename AHV08 beruf_erlernt_prestige_tr
label var beruf_erlernt_prestige_tr "AHV08: Prestige of the profession learned by the stepfather (Trei)"

rename AHV33 beruf_erlernt_prestige_wg
label var beruf_erlernt_prestige_wg "AHV33: Prestige of the profession learned by the stepfather (Wegener)"

** Occupation when index person was 15 years old

rename AHV12 beruf_ip15j_jn
recode beruf_ip15j_jn 8/9 = .

rename AHV13 beruf_ip15j 
label var beruf_ip15j "AHV13: Occupation that the biological father practiced when IP was 15 years old (ISCO)"
recode beruf_ip15j 8/9 = .

rename AHV14 beruf_ip15j_prestige_tr 
label var beruf_ip15j_prestige_tr "AHV14: Prestige of the profession that the stepfather practiced when IP was 15 years old (TREI)"

rename AHV34 beruf_ip15j_prestige_wg 
label var beruf_ip15j_prestige_wg "AHV34: Prestige of the profession that the stepfather practiced when IP was 15 years old (Wegener)"

** Occupation before index person was 15 years olds (if father was not gainfully employed when IP was 15 years old)

rename AHV18 beruf_vip15j 
label var beruf_vip15j "AHV18: Occupation that the stepfather practiced before the IP was 15 years old (ISCO)"
recode beruf_vip15j 8/9 = .

rename AHV19 beruf_vip15j_prestige_tr 
label var beruf_vip15j_prestige_tr "AHV19: Prestige of the profession practiced by the stepfather before IP 15 yrs old (TREI)"

rename AHV35 beruf_vip15j_prestige_wg 
label var beruf_vip15j_prestige_wg "AHV19: Prestige of the profession practiced by the stepfather before IP 15 yrs old (Wegener)"

* Occupation before retirement/death

rename AHV23 beruf_vRuhe 
label var beruf_vRuhe "AHV23: Profession that the stepfather practiced before retirement/death"
recode beruf_vRuhe 8/9 = .

rename AHV24 beruf_vRuhe_prestige_tr 
label var beruf_vRuhe_prestige_tr "AHV24: Prestige of the profession practiced by the stepfather before retirement/death (TREI)"

rename AHV36 beruf_vRuhe_prestige_wg 
label var beruf_vRuhe_prestige_wg "AHV36: Prestige of the profession practiced by the stepfather before retirement/death (Wegener)"

drop AHV* AIDHV

gen index = 1003

compress

save "$widowsghs/processed/intermediate/B_Stiefvater_CS_LV2A.dta", replace



***********************************************
* Merge Dataset
***********************************************

clear

use "$widowsghs/processed/intermediate/A_Indexperson_CS_LV2A.dta", replace
forvalues t = 1/3 {
append using "$widowsghs/processed/intermediate/A_Ehepartner`t'_CS_LV2A.dta"
}
append using "$widowsghs/processed/intermediate/B_Mutter_CS_LV2A.dta"
append using "$widowsghs/processed/intermediate/B_Stiefmutter_CS_LV2A.dta"
append using "$widowsghs/processed/intermediate/B_Vater_CS_LV2A.dta"
append using "$widowsghs/processed/intermediate/B_Stiefvater_CS_LV2A.dta"

sort AIDN index

rename AIDN fid
label var fid "Family ID"

gen lv2a = 1

sort fid index
compress
save "$widowsghs/processed/intermediate/LV2A_CS_combined.dta", replace

